<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="关键字" prop="keyword">
          <el-input v-model="filterForm.keyword" clearable placeholder="项目ID/项目标题/项目内容" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="状态" prop="status">
            <el-radio-group v-model="filterForm.status">
              <el-radio-button label="0">全部</el-radio-button>
              <el-radio-button label="1">已处理</el-radio-button>
              <el-radio-button label="2">待处理</el-radio-button>
              <el-radio-button label="3">处理中</el-radio-button>
            </el-radio-group>
        </el-form-item>
      </el-form>
      <el-button @click="handleFilter()">搜索</el-button>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      @sort-change="sortChange"
    >
      <el-table-column label="ID" prop="id" sortable="custom" align="center">
        <template slot-scope="{row}">
          <span>{{ row.symbol }}</span>
        </template>
      </el-table-column>
      <el-table-column label="资金" min-width="150px">
        <template slot-scope="{row}">
          <div>总额：￥{{ row.amount }}</div>
          <div>现金：￥{{ row.cash }}</div>
        </template>
      </el-table-column>
      <el-table-column label="利润" min-width="150px">
        <template slot-scope="{row}">
          <div>资产：￥{{ row.capital }}</div>
          <div v-if="row.profit < 0" style="color:red">利润：￥{{ row.profit }}</div>
          <div v-if="row.profit > 0" style="color:green">利润：￥{{ row.profit }}</div>
          <div v-else>利润：￥{{ row.profit }}</div>
        </template>
      </el-table-column>
      <el-table-column label="资金往来" min-width="150px">
        <template slot-scope="{row}">
          <div>存款：￥{{ row.deposit }}</div>
          <div>取款：￥{{ row.withdraw }}</div>
        </template>
      </el-table-column>
      <el-table-column label="账户类型">
        <template slot-scope="{row}">
          <span v-if="row.simulation == 1" style="color:red">模拟</span>
          <span v-else style="color:green">真实</span>
        </template>
      </el-table-column>
      <el-table-column label="最后更新" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.updatedAt }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="200px">
        <template slot-scope="{row}">
            <el-button type="text" @click="hiddenDepositWrapper=true;depositForm.accountID=row.ID" >存款</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getList" />


    <el-dialog
      title="存款"
      :visible.sync="hiddenDepositWrapper"
      :close-on-click-modal="false"
      width="50%">
      <el-form ref="filterForm" :model="depositForm"  label-position="left" label-width="100px">
        <el-form-item label="金额" prop="amount">
          <el-input-number v-model="depositForm.amount" :min="100" :step="100" :max="1000000" label="金额"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="hiddenDepositWrapper = false;depositForm.amount=100">取 消</el-button>
        <el-button type="primary" @click="handleDepositSubmit()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getList} from '@/api/finance/account'

export default {
  name: 'faultinessAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      socket:"",
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: false,
      connected:"loading",
      depositForm:{
        amount:100
      },
      hiddenDepositWrapper:false,
      filterForm: {
        page: 1,
        size: 10,
        simulation: 2,
        status: '0'
      }
    }
  },
  created() {
    this.getList()
  },
  destroyed(){
    this.close()
  },
  methods: {
    handleDepositSubmit:function(){
      this.send({
        "conversationType":"finance.deposit.save",
        "message":this.depositForm,
        "target":{"id":"3"}
      })
    },
    getList:function(){
      let _this = this;
      console.log(_this.filterForm)
      getList(_this.filterForm).then((response) => {
        console.log(response)
          if (response.code === 200) {
            this.list = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleFilter() {
      this.filterForm.page = 1
      this.getList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    }
  }
}
</script>
<style>

</style>